package com.xiaoqiudong.forum.common;

import com.fasterxml.jackson.annotation.JsonInclude;

/**
 * Created with IntelliJ IDEA
 * Descroption
 * User:dell
 * Date:2025-08-22
 * Time:14:26
 */
public class AppResult<T> {
    //状态码
    @JsonInclude(JsonInclude.Include.ALWAYS) // 不论任何情况都参加序列化
    private int code;
    //描述信息
    @JsonInclude(JsonInclude.Include.ALWAYS)
    private String message;
    //数据结果
    @JsonInclude(JsonInclude.Include.ALWAYS)
    private T data;

    /**
     * 构造方法
     * @param code
     * @param message
     * @param data
     */
    public AppResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    public AppResult(int code,String message){
        this(code,message,null);
    }

    /**
     * 成功
     */
    public static AppResult success(){
        return new AppResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage());
    }
    public static <T>AppResult<T> success(T data){
        return new AppResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(),data);
    }

    public static AppResult success(String message){
        return new AppResult(ResultCode.SUCCESS.getCode(), message);
    }
    public static <T>AppResult<T> success(String message,T data){
        return new AppResult(ResultCode.SUCCESS.getCode(), message,data);
    }

    /**
     * 失败
     */

    public static AppResult fail(){
        return new AppResult(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMessage());

    }
    public static AppResult fail(String message){
        return new AppResult(ResultCode.FAILED.getCode(), message);
    }

    public static AppResult fail(ResultCode resultCode){
        return new AppResult(resultCode.getCode(),resultCode.getMessage());
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
